@extends('backstage.layout.master')
@section('title', '赠品列表')
@section('content')
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try {
                ace.settings.check('breadcrumbs', 'fixed')
            } catch (e) {
            }
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a target="_blank" href="backstage/home">主页</a>
            </li>

            <li class="active">
                <a target="_blank" href="/backstage/gift/gift-list">赠品</a>
            </li>
            <li>
                赠品列表
            </li>
        </ul><!-- .breadcrumb -->
        <div class="nav-search" id="nav-search">
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="page-header">
            <h1>
                赠品
                <small>
                    <i class="icon-double-angle-right"></i>
                    赠品列表
                </small>
            </h1>
        </div>
        <div class="row">
            <div class="col-xs-12">
                <!-- PAGE CONTENT BEGINS -->
                <div class="table-responsive">
                    <table id="sample-table-1" class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th class="center">
                                <label>
                                    <input type="checkbox" class="ace">
                                    <span class="lbl"></span>
                                </label>
                            </th>
                            <th>赠品Id</th>
                            <th>赠品名称</th>
                            <th>赠品</th>
                            <th>赠品简介</th>
                            <th>参数简介</th>
                            <th>添加时间</th>
                            <th>更新时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>

                        <tbody>
                        @foreach ($gifts as $gift)
                            <tr class="" data-tr-id="{{$gift->id}}">
                                <td class="center">
                                    <label>
                                        <input type="checkbox" class="ace">
                                        <span class="lbl"></span>
                                    </label>
                                </td>
                                <td>{{isset($gift->id)?$gift->id:''}}</td>
                                <td>
                                    {{isset($gift->name)?$gift->name:''}}
                                </td>
                                <td><img src="{{isset($gift->thumbnail)?$gift->thumbnail:''}}" width="200" ></td>
                                <td>
                                    {{isset($gift->gift_desc)?str_limit($gift->gift_desc, $limit = 10, $end = '...'):''}}
                                </td>
                                <td>
                                    {{isset($gift->param_desc)?str_limit($gift->param_desc, $limit = 10, $end = '...'):''}}
                                </td>
                                <td>
                                    {{isset($gift->created_at)?date('Y-m-d H:i:s',$gift->created_at):''}}
                                </td>
                                <td>
                                    {{isset($gift->updated_at)?date('Y-m-d H:i:s',$gift->updated_at):''}}
                                </td>
                                <td>
                                    <div class="visible-md visible-lg hidden-sm hidden-xs btn-group">

                                        <button onclick="javascript:window.location.href='{{asset('')}}backstage/gift/gift-update?gift_id={{isset($gift->id)?$gift->id:0}}';" class="btn btn-xs btn-info" data-rel="tooltip" title="修改">
                                            <i class="icon-edit bigger-120"></i>
                                        </button>

                                        <button class="btn btn-xs btn-danger" data-delete="{{isset($gift->id)?$gift->id:0}}" data-rel="tooltip" title="删除">
                                            <i class="icon-trash bigger-120"></i>
                                        </button>
                                        <button onclick="javascript:window.location.href='{{asset('')}}backstage/gift/gift-use-range?gift_id={{isset($gift->id)?$gift->id:0}}';" class="btn btn-xs btn-info" data-rel="tooltip" title="使用范围">
                                            <i class="icon-zoom-in bigger-120"></i>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
                <div class="row">
                    <div class="col-sm-6">
                        <div class="dataTables_info" id="sample-table-2_info"></div>
                    </div>
                    <div class="col-sm-6">
                        <div class="dataTables_paginate paging_bootstrap">
                            <?php echo $gifts->render(); ?>
                        </div>
                    </div>
                </div>
                <!-- PAGE CONTENT ENDS -->
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.page-content -->
@stop
@section('script')
    <script type="text/javascript">
        $(function () {
            $('[data-rel=tooltip]').tooltip();
            $('[data-delete]').click(function() {
                var gift_id = $(this).attr("data-delete");
                console.log(gift_id);
                if(gift_id!=''&&gift_id!=undefined) {
                    swal({
                        title: '确定删除赠品？！',
                        text: "",
                        type: "warning",
                        showCancelButton: true,
                        confirmButtonColor: "#DD6B55",
                        confirmButtonText: "确定",
                        cancelButtonText: "取消",
                        closeOnConfirm: true,
                        closeOnCancel: true
                    }, function () {
                        $.ajax({
                            type: "post",
                            url: "backstage/gift/delete-gift",
                            data: {
                                gift_id: gift_id,
                                _token: "{{csrf_token()}}"
                            },
                            success: function (res) {
                                if (res.state == 1) {
                                    swal({
                                        title: "删除成功！",
                                        text: "",
                                        type: "success",
                                        timer: 2000
                                    });
                                    $('[data-tr-id=' + gift_id + ']').remove();
                                } else {
                                    swal({
                                        title: res.message,
                                        text: "",
                                        type: "error",
                                        timer: 2000
                                    });
                                }
                            },
                            error: function () {
                                swal({
                                    title: "系统繁忙！",
                                    text: "",
                                    type: "error",
                                    timer: 3000
                                });
                            }
                        });
                    });
                }
             });
            $('table th input:checkbox').on('click' , function(){
                var that = this;
                $(this).closest('table').find('tr > td:first-child input:checkbox')
                        .each(function(){
                            this.checked = that.checked;
                            $(this).closest('tr').toggleClass('selected');
                        });

            });
        });
    </script>
@stop